package com.example.lottery_system.common.config;

import com.example.lottery_system.common.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.Arrays;
import java.util.List;

/**
 * 拦截器的操作注册
 */

@Configuration
public class WebConfig  implements WebMvcConfigurer {
    @Autowired
    LoginInterceptor loginInterceptor;
//    保证除了登录和注册页面 其他都要拦截
    List<String> exclude = Arrays.asList(
            "/**/*.html",
            "/css/**",
            "/js/**",
            "/pic/**",
            "/*.jpg",
            "/*.png",
            "/register" ,
            "/favicon.ico",
            "/login/**",
            "/register",
            "/winning-records/show"
    );

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")
                .excludePathPatterns(exclude);
    }
}
